package com.lxf.cn.web;

import com.lxf.cn.redis.RedisUitls;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * Created by liaoxuefeng on 2018/11/12.
 */


@Controller
@RequestMapping("/redis")
public class RedisController {

    @Autowired
    RedisUitls redisUitls;


    /**
     * redis
     */
    @GetMapping("/set")
    public @ResponseBody
    String redis() {
        //设置3分钟
      String s =   redisUitls.setValueAndLifeCycle("a", 180, "x");
        System.out.printf("~~~~~~~~~~~~~~~~~~~"+s);
        redisUitls.setString("test", "不删除第一额");
        String result = redisUitls.getString("test");
        if (StringUtils.isNotBlank(result)) {
            System.out.printf("缓存中获取数据" + result);
        } else {
            System.out.printf("缓存数据不存着");
        }
        return "ok" ;
    }



}
